package threadBaseUse;

/**
 * @description: 多线程案例
 * @author: Liuwanqing
 * @date: 2022-10-14 15:54
 */
public class Thread03 {
    public static void main(String[] args) {
        T t3 = new T();
        Thread thread1 = new Thread(t3);
        Thread thread2 = new Thread(t3);
        thread1.start();
        thread2.start();

    }
}

class T implements Runnable {
    int count = 0;
    @Override
    public void run() {
        while (true) {
            System.out.println("hello, 线程1 " + (++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if(count == 10){
                break;
            }
        }
    }
}

class T2 implements Runnable {
    int count = 0;
    @Override
    public void run() {
        while (true) {
            System.out.println("hi, 线程2 " + (++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if(count == 5){
                break;
            }
        }
    }
}
